

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from ops import OperatorBoxItem,OperatorItem

class ArithmeticItem(OperatorBoxItem):
    group = "arithmetic"
    def __init__(self,x,y,inputs,outputs,name):
        OperatorBoxItem.__init__(self,x,y,inputs,outputs,name)

class Add(ArithmeticItem):
    name = "Add"
    def __init__(self,x,y):
        ArithmeticItem.__init__(self,x,y,["A","B"],["A+B"],"Add")
        self.setToolTip("Adds inputs")
    def process(self):
        self.outputs[0].value = self.inputs[0].value+self.inputs[1].value

class Sub(ArithmeticItem):
    name = "Sub"
    def __init__(self,x,y):
        ArithmeticItem.__init__(self,x,y,["A","B"],["A-B"],"Sub")
        self.setToolTip("Computes A - B")
    def process(self):
        self.outputs[0].value = self.inputs[0].value - self.inputs[1].value

class Mul(ArithmeticItem):
    name = "Multiply"
    def __init__(self,x,y):
        ArithmeticItem.__init__(self,x,y,["A","B"],["A*B"],"Multiply")
        self.setToolTip("Computes A times B")
    def process(self):
        self.outputs[0].value = self.inputs[0].value * self.inputs[1].value

class Div(ArithmeticItem):
    name = "Divide"
    def __init__(self,x,y):
        ArithmeticItem.__init__(self,x,y,["A","B"],["A/B"],"Divide")
        self.setToolTip("Computes A / B")
    def process(self):
        self.outputs[0].value = float(self.inputs[0].value)/float(self.inputs[1].value)

class SumDiff(ArithmeticItem):
    name = "Sum-Diff"
    def __init__(self,x,y):
        ArithmeticItem.__init__(self,x,y,["A","B"],["A+B","A-B"],"SumDiff")
        self.setToolTip("Sum and Difference")
    def process(self):
        self.outputs[0].value = self.inputs[0].value + self.inputs[1].value
        self.outputs[1].value = self.inputs[0].value - self.inputs[1].value
    
ops = [Add,Sub,Mul,Div,SumDiff]
